cmake_minimum_required(VERSION 3.25.1)

project(Online_Office_Chart VERSION 1.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)

add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")

set(CMAKE_AUTOMOC ON)

set(CMAKE_AUTORCC ON)

set(CMAKE_AUTOUIC ON)

if (NOT CMAKE_GENERATOR)
  set(CMAKE_GENERATOR "Visual Studio 16 2019" CACHE INTERNAL "Default generator" FORCE)
endif ()

find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Sql Network Svg Quick)

if(Qt6_FOUND)
    message(STATUS "Found Qt6: ${Qt6_VERSION}")
else()
    message(FATAL_ERROR "Qt6 not found")
endif()

file(GLOB SRC_FILES
    "${PROJECT_SOURCE_DIR}/*")
file(GLOB RESOURCE_FILES
    "${PROJECT_SOURCE_DIR}/resource/*")
file(GLOB FLOW_FILES
    "${PROJECT_SOURCE_DIR}/flow/*")
file(GLOB FLOW_SHAPE_FILES
    "${PROJECT_SOURCE_DIR}/flow/shape/*")
file(GLOB FLOW_PAINT_FILES
    "${PROJECT_SOURCE_DIR}/flow/paint/*")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 

add_library(
	Online_Office_Chart_Library
	${SRC_FILES} 
	${RESOURCE_FILES}
	${FLOW_FILES} 
	${FLOW_SHAPE_FILES} 
	${FLOW_PAINT_FILES}
)

qt6_add_resources(Online_Office_Chart_Resource ${PROJECT_SOURCE_DIR}/resource/*)

target_link_libraries(
	Online_Office_Chart_Library
	PRIVATE 
	Qt6::Core 
	Qt6::Gui 
	Qt6::Widgets 
	Qt6::Sql 
	Qt6::Svg 
	Qt6::Network 
	Qt6::Quick
)

# 设置cmake输出目录
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/exe)

#进行目录整理
file(GLOB_RECURSE  HEAD *.h)
file(GLOB_RECURSE  SOURCE *.cpp)
set(AllFile ${HEAD} ${SOURCE})
foreach(fileItem ${AllFile})       
    # Get the directory of the source file
    get_filename_component(PARENT_DIR "${fileItem}" DIRECTORY)
    # Remove common directory prefix to make the group
    string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" GROUP "${PARENT_DIR}")
    # Make sure we are using windows slashes
    string(REPLACE "/" "\\" GROUP "${GROUP}")
    # Group into "Source Files" and "Header Files"
    set(GROUP "${GROUP}")
    source_group("${GROUP}" FILES "${fileItem}")
endforeach()


